Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Inter connect local machines together with a Express like socket router. Data transfer is cipphered with Diffie Hellman algorithm (dynamic public / private key exchange between peers based on a shared password).
Instanciate new peer:
var Synapsis = require('synapsis');
var synapse = new Synapsis({
namespace: 'namespace-name',
password: 'long-password-16-random-caracters-recommended',
// Identity will be shared to all peers
identity: {
name : require('os').hostname()
}
});
// Now start the peer
synapse.start();
Now expose socket routes that can be triggered by other peers:
synapse.router('command:restart', () => {
console.log('Got Restart');
});
synapse.router('command:sync_db', (new_db, reply) => {
fs.writeFile('current_db.json', new_db, (err) => {
if (err)
return reply(err);
reply(null, 'DB Synced');
});
});
To send actions to other peers:
// Broadcast a message to all nodes (w/o current) and do not wait for response
synapse.broadcast('command:restart');
// Broadcast a message + data to all nodes (w/o current) and do not wait for response
synapse.broadcast('command:restart', { some : 'data' });
// Broadcast a message to all nodes (w/o current) and receive messages from each (RPC like)
synapse.broadcast('command:sync_db', { my : { db : true } }, function(err, response, socket) {
console.log(`Err= ${err} Response = ${response} from = ${socket.identity.name}`);
});
Or send to a specific peer:
var peer = synapse.getPeers()[0];
synapse.send(peer.id, 'command:restart');
synapse.send(peer.id, 'command:restart', function(err, data, socket) {
console.log(err, data, socket.identity);
});
synapse.send(peer.id, 'command:restart', {mu : { db : true} }, function(err, data, socket) {
console.log(err, data, socket.identity);
});
synapse.on('peer:connected', function(identity, socket) {
console.log('New peer detected', identity);
});
synapse.on('peer:disconnected', function(identity) {
console.error(identity);
});
synapse.on('error', function(err) {
console.error(err);
});
synapse.on('ready', function() {
console.log('Peer Ready');
});
Checkout test/ folder for more examples/
MIT
FAQs
Automatic pub/sub over every possible network. It just works.
The npm package synapsis receives a total of 0 weekly downloads. As such, synapsis popularity was classified as not popular.
We found that synapsis demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.